import { defineStore } from "pinia";
import { ref } from "vue";

import { GetDefaultGameDirectory, GetDefaultJavaDirectory, GetIsDarkMode, GetPlayerName, GetUseFakeGameDirectory } from "../wailsjs/go/preference/Preference";

import { WindowSetBackgroundColour } from "../wailsjs/runtime/runtime";

export const usePreferenceStore = defineStore('Preference', () => {
    const fakeGameDirectory = ref(false)
    const isDarkTheme = ref(false)
    const playerName = ref("")
    const defaultGameDir = ref("")
    const defaultJavaDir = ref("")

    GetIsDarkMode().then((value) => {
        isDarkTheme.value = value

        if (value) {
            WindowSetBackgroundColour(24, 24, 28, 255)
        } else {
            WindowSetBackgroundColour(255, 255, 255, 255)
        }
    })

    GetPlayerName().then((value) => {
        playerName.value = value
    })

    GetUseFakeGameDirectory().then((value) => {
        fakeGameDirectory.value = value
    })

    GetDefaultGameDirectory().then((value) => {
        defaultGameDir.value = value
    })

    GetDefaultJavaDirectory().then((value) => {
        defaultJavaDir.value = value
    })

    return {
        fakeGameDirectory,
        isDarkTheme,
        playerName,
        defaultGameDir,
        defaultJavaDir
    }
})